<?php
error_reporting(E_ALL);
/*
	Copyright 2011 Kriss(krizoek) Admin@Bibelprat.Net
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

$username='databaseusername'; $password='databasepassword'; $database='database'; $database_host='127.0.0.1';

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
if(isset($_GET['getstrong'])) { $getstrong=$_GET['getstrong']; } else { $getstrong=''; }
//function iif($tst,$cmp,$bad) { return(($tst == $cmp)?$cmp:$bad); }
$shortbibleworks = "Gen Exo Lev Num Deu Jos Jdg Rut 1Sa 2Sa 1Ki 2Ki 1Ch 2Ch Ezr Neh Est Job Psa Pro Ecc Sol Isa Jer Lam Eze Dan Hos Joe Amo Oba Jon Mic Nah Hab Zep Hag Zec Mal Mat Mar Luk Joh Act Rom 1Co 2Co Gal Eph Phi Col 1Th 2Th 1Ti 2Ti Tit Phm Heb Jam 1Pe 2Pe 1Jo 2Jo 3Jo Jud Rev 1Es Jdt Tob 1Ma 2Ma 3Ma 4Ma Ode Wis Sip Sir Pss Bar Epj Sus Bel Pra Dng Prm Psx Lao 4Es Esg Jsa Jda Tbs Sut Dat Bet WCF WLC WSC 1Cl 2Cl"; 
$shortdrupal = "GEN EXO LEV NUM DEU JOS JUG RUT 1SM 2SM 1KG 2KG 1CH 2CH EZR NEH EST JOB PS PRO ECC SON ISA JER LAM EZE DAN HOS JOE AMO OBA JON MIC NAH HAB ZEP HAG ZEC MAL MAT MAK LUK JHN ACT ROM 1CO 2CO GAL EPH PHL COL 1TS 2TS 1TM 2TM TIT PHM HEB JAM 1PE 2PE 1JN 2JN 3JN JUD REV";
//$dbbooksorg = "Genesis Exodus Leviticus Numbers Deuteronomy Joshua Judges Ruth 1Samuel 2Samuel 1Kings 2Kings 1Chronicles 2Chronicles Ezra Nehemiah Esther Job Psalm Proverbs Ecclesiastes Songofsolomon Isaiah Jeremiah Lamentations Ezekiel Daniel Hosea Joel Amos Obadiah Jonah Micah Nahum Habakkuk Zephaniah Haggai Zechariah Mal Matthew Mark Luke John Acts Romans 1Corinthians 2Corinthians Galatians Ephesians Philippians Colossians 1Thessalonians 2Thessalonians 1Timothy 2Timothy Titus Philemon Hebrews James 1Peter 2Peter 1John 2John 3John Jude Revelation";
//$boker = "1Mosebok 2Mosebok 3Mosebok 4Mosebok 5Mosebok Josva Dommerne Rut 1Samuelsbok 2Samuelsbok 1Kongebok 2Kongebok 1Krønikebok 2Krønikebok Esra Nehemja Ester Job Salmenesbok Salomosordspråk Forkynneren Høysangen Jesaja Jeremia Klagesangene Esekiel Daniel Hosea Joel Amos Obadja Jona Mika Nahum Habakkuk Sefanja Haggai Sakarja Malaki Matteus Markus Lukas Johannes Apostelgjerningene Romerne 1Korinterbrev 2Korinterbrev Galaterne Efeserne Filipperne Kolosserne 1Tessaloniker 2Tessaloniker 1Timoteus 2Timoteus Titus Filemon Hebreerne Jakob 1Peters 2Peters 1Johannes 2Johannes 3Johannes Judas Åpenbaringen";
$bokers = "1Mos 2Mos 3Mos 4Mos 5Mos Josv Domm Rut 1Sam 2Sam 1Kon 2Kon 1Krø 2Krø Esra Nehe Este Job Salm Salo Fork Høy Jesa Jere Klag Esek Dani Hose Joel Amos Obad Jona Mika Nahu Haba Sefa Hagg Saka Mala Matt Mark Luka Joha Apos Rome 1Kor 2Kor Gala Efes Fili Kolo 1Tes 2Tes 1Tim 2Tim Titu File Hebr Jako 1Pet 2Pet 1Joh 2Joh 3Joh Juda Åpe";
$books = "Gen Exo Lev Num Deu Jos Jud Rut 1Sa 2Sa 1Ki 2Ki 1Ch 2Ch Ezr Neh Est Job Psa Pro Ecc Son Isa Jer Lam Eze Dan Hos Joe Amo Oba Jon Mic Nah Hab Zep Hag Zec Mal Mat Mar Luk Joh Act Rom 1Co 2Co Gal Eph Phili Col 1Th 2Th 1Ti 2Ti Tit Phile Heb Jam 1Pe 2Pe 1Jo 2Jo 3Jo Jud Rev";
//$shortlebNT = "Mt Mk Lk Jn Ac Ro 1Co 2Co Ga Eph Php Col 1Th 2Th 1Ti 2Ti Tt Phm Heb Jas 1Pe 2Pe 1Jn 2Jn 3Jn Jud Re";
$a_shortbibleworks = explode(' ', $shortbibleworks);
$a_shortdrupal = explode(' ', $shortdrupal);
$a_books = explode(' ', $books);
//$a_boker = explode(' ', $boker);
$a_bokers = explode(' ', $bokers);
//$a_dbbooksorg = explode(' ', $dbbooksorg);
//$a_shortlebNT = explode(' ', $shortlebNT);
function tthtml($txt) {
  $txt = str_replace('&quot;','"',$txt);
  $txt = str_replace('&lt;','<',$txt);
  $txt = str_replace('&gt;','>',$txt);
  $txt = str_replace('&amp;','&',$txt);
  return($txt);
}

$link=mysql_connect($database_host, $username, $password) or die ('Error connecting to mysql');
mysql_select_db($database, $link);
mysql_set_charset('utf8',$link);

// user check
$usercheckip="SELECT `uid` FROM `sessions` WHERE `hostname`='".$_SERVER["REMOTE_ADDR"]."'";
$resultucheck=mysql_query($usercheckip, $link);
$numucheck=mysql_numrows($resultucheck);
for($i=0; $i<$numucheck; $i++) {
	$usercheckid=mysql_result($resultucheck,$i,"uid");
	if ($usercheckid !== "0") { $userloggedintoip = "SELECT `name` FROM `users` WHERE `uid`='$usercheckid'"; }
}
if (isset($userloggedintoip)) {
	$resultucheck=mysql_query($userloggedintoip, $link);
	$numucheck=mysql_numrows($resultucheck);
	for($i=0; $i<$numucheck; $i++) {
		$userfoundincheck=mysql_result($resultucheck,$i,"name");
	}
}
//if (isset($userfoundincheck)) {echo $userfoundincheck;}
 //<- user check

if(isset($_GET['bk'])) { $book=$_GET['bk']; } else { $book='GEN'; }
if(isset($_GET['xref'])) { echo " Function on hold.<br>Reason: Unable to find a good database. <br>Do you know of a good readable file that have crossreferences ? or would you like to help put together one?<br>"; }
if(isset($_GET['ch'])) { $chbf=$_GET['ch']; } else { $chbf=''; }
if(isset($_GET['b'])) { $bible=$_GET['b']; } else { $bible='1'; }
if(isset($_GET['setbookmark'])) { $setbookmark=$_GET['setbookmark']; } else { $setbookmark=''; }
if(isset($_GET['bookmark'])) { $bookmark=$_GET['bookmark']; } else { $bookmark=''; }
if(isset($_GET['userfeatures'])) { $userfeatures=$_GET['userfeatures']; } else { $userfeatures=''; }
if(isset($_GET['setnote'])) { $setnote=$_GET['setnote']; } else { $setnote=''; }
if(isset($_GET['note'])) { $note=$_GET['note']; } else { $note=''; }
if(isset($_GET['setfavorite'])) { $setfavorite=$_GET['setfavorite']; } else { $setfavorite=''; }
if(isset($_GET['favorite'])) { $favorite=$_GET['favorite']; } else { $favorite=''; }
if (is_array($bible)) {
	if (count($bible)=== 1) { $bible=$bible[0]; $ismultibiblecheck=''; }
	else { $ismultibiblecheck=$_GET['b']; $bible=$bible[0]; }
}
else { $ismultibiblecheck = array(); }
if (!empty($ismultibiblecheck)) { $biblel = ""; foreach($ismultibiblecheck as $multi_b_t) { $biblel .= "&b[]=".$multi_b_t; } }
else { $biblel = "&b=".$bible; }
if(isset($_GET['c'])) { $chap=$_GET['c']; } else { $chap='1'; }
if(isset($_GET['tools'])) { $tools=$_GET['tools']; } else { $tools=''; } $toolshtml="&tools=1";
$prechap = $chap - 1; $postchap = $chap + 1;
if ($chbf == '<<') { $chap = $prechap; } elseif ($chbf == '>>') { $chap = $postchap; }

$searchonly = ''; $regex_enabled = ''; $searchbookspecific = ''; $searchbookmatched = ''; 
//if html search received
if(!empty($_GET['s']) or !empty($bookmark) or !empty($favorite) or (empty($setnote) and !empty($note))) {
	if(!empty($bookmark)) { $search = $bookmark; }
	elseif(!empty($favorite)) { $search = $favorite; }
	elseif(!empty($note)) { $search = $note; }
	elseif (!empty($_GET['s'])) { $search = $_GET['s']; }
	if (preg_match ("/^r:/i", $search)) {
		$search = preg_replace('/^r: |^r:/','',$search);
		$regex_enabled = '1';
	}
	$a_t_search = explode(' ', $search);
	$searchsum = sizeof($a_t_search);
	$t_book = $a_t_search[0];
	$token = array_search(strtolower($t_book),array_map('strtolower',$a_books));
	if ($token !== FALSE) { $b_name = $a_shortdrupal[$token]; } //+39 to make it the nt books
	elseif (!isset($b_name)) { $token = array_search(strtolower($t_book),array_map('strtolower',$a_bokers)); }
	if (!isset($b_name) && ($token !== FALSE)) { $b_name = $a_shortdrupal[$token]; }
	elseif (!isset($b_name)) { $token = array_search(strtolower($t_book),array_map('strtolower',$a_shortdrupal)); }
	if (!isset($b_name) && ($token !== FALSE)) { $b_name = $token; }
	elseif (!isset($b_name)) {$nobook = '1';}
	if (isset($b_name)) { $book = $b_name; } else { $book = $t_book; }
	if (($searchsum == 1) && !isset($nobook)) { $search = ''; }
	elseif(preg_match('/\d\:\d/',$search) && !isset($nobook)) {
		//echo $book." ".$searchsum."<br>";
		$search = explode(" ",$search); $book = explode(":",$search[1]);
		if (isset($search[2]) && isset($_GET['bookmark'])) { $bookmarkid = $search[2]; }
		$chap = $book[0]; $book = $search[0]; $search = '';
	} elseif (($searchsum == 2) && !isset($nobook)) {
		$chaps = $a_t_search[1]; $search = '';
		if ($chaps !== $chap) { $chap = $chaps; $chapdiff = '1'; }
	} else {$searchonly = '1';}
	if (preg_match('/\w{1,4}\(\d{1,5}\)/',$search,$searchbookmatch)) {
		$search = preg_replace('/\s\w{1,3}\(\d{1,5}\)/','',$search);
		$book = preg_replace('/\(\d{1,5}\)/','',$searchbookmatch[0]);
		$searchbookmatched = " AND `book`='".$book."'";
	}
	else { $nobookspecific = '1'; }
	//echo $search;
} else {$search='';}
// <- if html search received
if (isset($chapdiff)) { if ($chapdiff !== $chap) { $chap = $chaps; } }
if (isset($_SERVER['HTTP_REFERER']) && empty($chbf)) { if (!strpos($_SERVER['HTTP_REFERER'], "bk=$book") && empty($chapdiff)) {$chap ='1';} }
$wherestr = "";
if (($searchonly !== '1') or !isset($nobook)) { 
	if (empty($ismultibiblecheck)) { if ($bible != "*") { $wherestr .= $bible; } }
	else { // Interlinear bible function
		foreach($ismultibiblecheck as $multib) {
			if(empty($wherestr)) { $wherestr .= $multib; }
			else { $wherestr .= " ".$multib; }
		} $wherestr = preg_replace('/\s/',', ',$wherestr);
	}
	$mysqlbiblesearch = "SELECT * FROM `bible_context` WHERE `bid` IN($wherestr) AND `book`='$book' and `chapter`='$chap' ORDER BY `verse`"; 
}
else { // STRING SEARCH
	if ($regex_enabled) {
		$wherestr .= " AND context REGEXP '". $search . "'";
		$kwlist = array($search);
	} else {
		$kwl = explode(' ', $search);
		foreach ($kwl as $kw) {
			$kw = trim($kw);
			if ($kw == "") continue;
			$wherestr .= " AND";
			if (substr($kw, 0, 1) == '-') {
				$wherestr .= " NOT";
				$kw = substr($kw, 1);
			}
			$wherestr .= " UPPER(context) LIKE '%". strtoupper($kw). "%'";
			$kwlist[] = $kw;
		}
	}
	$wherestr = " linemark <> '*'" .$wherestr;
	$mysqlbiblesearchcountall = "SELECT `bid`,count(*) AS C FROM `bible_context` WHERE ". $wherestr ." group by `bid` ORDER BY `bid`";
	if (empty($ismultibiblecheck)) { if ($bible != "*") { $wherestr .= " AND `bid` = '". $bible. "'"; } }
	else { foreach($ismultibiblecheck as $multib) { $wherestr .= " AND `bid` = '".$multib. "'"; } }
	$mysqlbiblesearch = "SELECT * FROM `bible_context` WHERE ".$wherestr." $searchbookmatched ORDER BY `vsid`";
	$mysqlbiblesearchcount = "SELECT `book`,count(`book`) AS C FROM `bible_context` WHERE ". $wherestr ." group by `book` ORDER BY `vsid`";
}
//echo $mysqlbiblesearch;
// <- stringssearch

// HTML Bible List
if (empty($getstrong) && empty($setbookmark) && empty($userfeatures) && empty($setfavorite) && empty($setnote) && !isset($_GET['xref'])) { //check if features used
$result=mysql_query("SELECT * FROM `bible_list`", $link);
$num=mysql_numrows($result);
echo "<form action='index.php' method='get'><input type='text' name='s' value='$search'>";
if (!empty($tools) or !empty($ismultibiblecheck)) { echo "<select name='b[]' MULTIPLE SIZE=3>";}
else { echo "<select name='b'>";}
$bidarray=array();
for($i=0; $i<$num; $i++) {
 $bid=mysql_result($result,$i,"bid");
 //$bsn=mysql_result($result,$i,"bsn");
 $bname=mysql_result($result,$i,"bname");
 if (preg_match('/strong/i',$bname)) { if (isset($strongbiblelist)) { $strongbiblelist = $bid; } else { $strongbiblelist .= " ".$bid; } }
 //$lang=mysql_result($result,$i,"lang");
 //$serialversion=mysql_result($result,$i,"serialversion");
 $bidarray[$bid]=$bname;
 if (!empty($ismultibiblecheck) && in_array($bid,$ismultibiblecheck)) { $ssbible = 'selected'; }
 elseif ($bible === $bid) { $ssbible = 'selected'; }
 else { $ssbible = ''; }
 echo "<option value='$bid' $ssbible>$bid $bname</option>"; // bsn $bsn lang $lang 
}
if ($bible === "all") { $ssbible2 = selected; } else { $ssbible2 = ''; }
echo "<option value='all' $ssbible2>Search all Bibles</option></select>";
// <- HTML Bible List Selector

//HTML Book-list-Selector
$result2=mysql_query("SELECT DISTINCT `book` FROM `bible_context` WHERE `bid`='$bible' ORDER BY `vsid` ASC", $link);
$num2=mysql_numrows($result2);
echo "<select name='bk'>";	//TEMP
for($i=0; $i<$num2; $i++) {
	$sqbook=mysql_result($result2,$i,"book");
	if (strtolower($sqbook) === strtolower($book)) { $ssbible2 = 'selected'; } else { $ssbible2 = ''; }
	$token2 = array_search(strtolower($sqbook),array_map('strtolower',$a_shortdrupal));
	if ($token2 !== FALSE) { $b_name2 = $a_books[$token2]; } //+39 to make it the nt books
	else { $b_name2 = $sqbook; }
	echo "<option value='$sqbook' $ssbible2>$b_name2</option>";
}
echo "</select>";
// <- HTML Book-list-Selector


if (!empty($tools)) { 
	$toolshtml="";
	if (isset($userfoundincheck)) {
		// Bookmark list
		$result_bk=mysql_query("SELECT * FROM `bible_bookmarks` WHERE `user`='".$userfoundincheck."'", $link);
		//echo "SELECT * FROM `bible_bookmarks` WHERE `user`='".$userfoundincheck."'";
		$num_bk=mysql_numrows($result_bk);
		if($num_bk>0) {
			for($i=0; $i<$num_bk; $i++) {
				if ($i == 0) { echo "<select name='bookmark'><option value=''>Bookmarks</option>"; $bookmarkset='1'; }
				$bookmark=mysql_result($result_bk,$i,"bookmark");
				$sql_bookmark_id=mysql_result($result_bk,$i,"id");
				if (!empty($bookmark)) { echo "<option value='$bookmark $sql_bookmark_id'>$sql_bookmark_id $bookmark</option>"; }
			}
			if (isset($bookmarkset)) { echo "</select>"; }
		} // <- Bookmark list
		// Favorite list
		$result_fav=mysql_query("SELECT * FROM `bible_favorites` WHERE `user`='".$userfoundincheck."'", $link);
		//echo "SELECT * FROM `bible_bookmarks` WHERE `user`='".$userfoundincheck."'";
		$num_fav=mysql_numrows($result_fav);
		if($num_fav>0) {
			for($i=0; $i<$num_fav; $i++) {
				if ($i == 0) { echo "<select name='favorite'><option value=''>Favorites</option>"; $favoriteset='1'; }
				$sql_favoriteverse=mysql_result($result_fav,$i,"favoriteverse");
				$sql_favorite_id=mysql_result($result_fav,$i,"id");
				if (!empty($sql_favoriteverse)) { echo "<option value='$sql_favoriteverse $sql_favorite_id'>$sql_favorite_id $sql_favoriteverse</option>"; }
			}
			if (isset($favoriteset)) { echo "</select>"; }
		} // <- Favorite list
		// Note list
		$result_note=mysql_query("SELECT * FROM `bible_notes` WHERE `user`='".$userfoundincheck."'", $link);
		//echo "SELECT * FROM `bible_notes` WHERE `user`='".$userfoundincheck."'";
		$num_note=mysql_numrows($result_note);
		if($num_note>0) {
			for($i=0; $i<$num_note; $i++) {
				if ($i == 0) { echo "<select name='note'><option value=''>Notes</option>"; $notesset='1'; }
				$sql_note_verse=mysql_result($result_note,$i,"verse");
				$sql_note_id=mysql_result($result_note,$i,"id");
				if (!empty($sql_note_verse)) { echo "<option value='$sql_note_verse $sql_note_id'>$sql_note_id $sql_note_verse</option>"; }
			}
			if (isset($notesset)) { echo "</select>"; }
		} // <- Favorite list
	}
}
//echo "<a href=".$_SERVER['PHP_SELF']."?s=".$biblel."&bk=".$sqlbook."&ch=&#62;&#62;&c=".$chap.">&#62;&#62;</a><br>";
echo "<input type='submit' value='Go' /><input name='ch' type='submit' value='<<'><input name='ch' type='submit' value='>>'><input type='hidden' name='c' value='$chap'>";
echo " <a href=".$_SERVER['PHP_SELF']."?s=".preg_replace('/\s/','+',$search).$biblel."&bk=".$book."&c=".$chap.$toolshtml.">TOOLS</a>";
if (!empty($tools)) { echo " <a href=".$_SERVER['PHP_SELF'].">HOME</a> <a href='http://bibel.thruhere.net/chat'>CHAT</a> <a href='/user/login'>LOGIN</a>"; }
// <- Bookmark list
echo "</form>";

// Resultsallbibles
if (!empty($ssbible2) && isset($mysqlbiblesearchcountall)) {
	$result3=mysql_query($mysqlbiblesearchcountall, $link);
	$num3=mysql_numrows($result3);
	for($i=0; $i<$num3; $i++) {
		$sqlcountbible=mysql_result($result3,$i,"bid");
		$sqlcountversenum=mysql_result($result3,$i,"C");
		//echo $sqlcountbible." ".$bidarray[$sqlcountbible]."(".$sqlcountversenum.") ";
		echo "<a href=".$_SERVER['PHP_SELF']."?s=".preg_replace('/\s/','+',$search)."&b=".$sqlcountbible."&bk=".$book."&ch=&#62;&#62;&c=".$chap.">".$sqlcountbible." ".$bidarray[$sqlcountbible]."(".$sqlcountversenum.")</a> ";
	}
	echo "<br><br>"; 
}
// <- Resultsallbibles

//SearchResultsNumber
if (isset($mysqlbiblesearchcount)) {
	$result4=mysql_query($mysqlbiblesearchcount, $link);
	$num4=mysql_numrows($result4);
	for($i=0; $i<$num4; $i++) {
		$sqlcountbook=mysql_result($result4,$i,"book");
		$sqlcountversenum=mysql_result($result4,$i,"C");
		if ($sqlcountbook === "MAT") { echo "<br>"; }
		echo "<a href=".$_SERVER['PHP_SELF']."?s=".preg_replace('/\s/','+',$search)."+".$sqlcountbook."(".$sqlcountversenum.")&b=".$bible."&bk=".$book."&c=".$chap.">".$sqlcountbook."(".$sqlcountversenum.")</a> ";
	}
	echo "<br><br>"; 
}
// <- SearchResultNumber

//BibleContentParser
if ((empty($searchonly) and empty($tools)) or (!empty($searchbookmatched) and empty($tools))) {
	if (!empty($strongbiblelist)) {
		if (!empty($ismultibiblecheck)) {
			if (!is_array($strongbiblelist)) { $strongbiblelist = explode(" ",$strongbiblelist); }
			foreach($strongbiblelist as $strongbsearch) { if(array_search($strongbsearch,$ismultibiblecheck,TRUE)) { $parse_strongb = '1'; } }
			//else { if(array_search($strongbsearch,$ismultibiblecheck,TRUE)) { $parse_strongb = '1'; } }
			//if (preg_match("/(^".preg_quote($bible,"/")."\s)|(\s".preg_quote($bible,"/")."\s)|(\s".preg_quote($bible,"/")."$)/",$strongbiblelist)) { $parse_strongb = '1'; }
			//if(preg_grep('/strong/i', $ismultibiblecheck)) { stripos($bible'strong') }
		}
		elseif (preg_match("/(^".preg_quote($bible,"/")."\s)|(\s".preg_quote($bible,"/")."\s)|(\s".preg_quote($bible,"/")."$)/",$strongbiblelist)) { $parse_strongb = '1'; }
		//".preg_quote($bible,"/")."
	}
	// strong links 
	$result5=mysql_query($mysqlbiblesearch, $link);
	$num5=mysql_numrows($result5);
	for($i=0; $i<$num5; $i++) {
		$sqlchapter=mysql_result($result5,$i,"chapter");
		$sqlversenum=mysql_result($result5,$i,"verse");
		$sqlbook=mysql_result($result5,$i,"book");
		$sqlcontext=mysql_result($result5,$i,"context");
		if (isset($parse_strongb)) {
			$sqlcontext = preg_replace("/<([^>]\d{4})>/i","<a target='middleframe' href='".$_SERVER['PHP_SELF']."/?getstrong=$1' >	&#8226;</a>",$sqlcontext);
		}
		// <- strong links
		//<[^>](\d{4})>
		$sqlverselink = $sqlbook." ".$sqlchapter.":".$sqlversenum;
		if (!isset($mysqlbiblesearchcount) && !isset($iframe1) && ($i >= ($num5 / 2))) { echo "<iframe name='middleframe' src='test.php' width='100%' height='13%' frameborder='0'></iframe>"; $iframe1 = '1'; }
		if (!empty($searchbookmatched)) {
			//$sqlverse = preg_replace('/\s/','+',($sqlbook.' '.$sqlchapter));
			$sqlchapter2 = $sqlchapter - 1;
			echo "<a href=".$_SERVER['PHP_SELF']."?s=&b=".$bible."&bk=".$sqlbook."&ch=&#62;&#62;&c=".$sqlchapter2.">".$sqlverselink."</a> ".tthtml($sqlcontext)."<br>";
		}else {
			if (!empty($userfoundincheck)) { $sqlverselink = "<a target='middleframe' href=".$_SERVER['PHP_SELF']."?userfeatures=".preg_replace('/\s/','+',$sqlverselink).">".$sqlverselink."</a>"; }
			echo $sqlverselink." ".tthtml($sqlcontext)."<br>";
		}
	}
	if (empty($sqlbook)) { if (!empty($book)) { $sqlbook=$book; } else { $sqlbook=""; } echo "No more chapters, try next book:)<br>";}
	echo "<a href=".$_SERVER['PHP_SELF']."?s=".$biblel."&bk=".$sqlbook."&ch=&#62;&#62;&c=".$chap.">&#62;&#62;</a><br>";
	echo "<br>".$num5." Verse/s<br>";
	//if (!isset($mysqlbiblesearchcount)) { echo "<a href='http://google.com' target='middleframe'>IframeLinkTest</a>";}
}
} // <- check if getstrong, setbookmark
elseif(!empty($getstrong)) {
	//SELECT * FROM `bible_strongnumber` WHERE `sn`='$getstrong'
	$result6=mysql_query("SELECT * FROM `bible_strongnumber` WHERE `sn`='".$getstrong."'", $link);
	$num6=mysql_numrows($result6);
	for($i=0; $i<$num6; $i++) {
		$strongdefinition=mysql_result($result6,$i,"content");
		$strongdefinition=preg_replace("(\r\n)","<br>",$strongdefinition);
		if (!empty($strongdefinition)) { echo $strongdefinition."<br>"; }
	}
}
elseif(!empty($setbookmark) && !empty($userfoundincheck)) { // set/remove bookmark
	// $setbookmark $userfoundincheck
	//"DELETE FROM `bible_bookmarks` WHERE `id` = '".$setbookmark."'"
	$result7=mysql_query("SELECT id FROM `bible_bookmarks` WHERE `bookmark`='".$setbookmark."' AND `user`='".$userfoundincheck."'", $link);
	$num7=mysql_numrows($result7);
	if ($num7>=1) { $mysqldo = "DELETE FROM `bible_bookmarks` WHERE `bookmark` = '".$setbookmark."' AND `user`='".$userfoundincheck."'"; }
	else { $mysqldo ="INSERT INTO `b`.`bible_bookmarks` (`id`, `bookmark`, `user`, `datetime`) VALUES (NULL, '".$setbookmark."', '".$userfoundincheck."', NOW())"; }
	$result7=mysql_query($mysqldo,$link);
	echo "Bookmark Edited";
	//echo $mysqldo."<br>";
	// for($i=0; $i<$num7; $i++) { }
} // <- set/remove bookmark
elseif(!empty($setnote) && !empty($userfoundincheck)) { // set/update/remove note		///UNDER CONSTRUCTION
	$result8=mysql_query("SELECT * FROM `bible_notes` WHERE `verse`='".$note."' AND `user`='".$userfoundincheck."'", $link);
	$num8=mysql_numrows($result8);
	if ($num8>=1) {
		for($i=0; $i<$num8; $i++) {
			$sqlnote=mysql_result($result8,$i,"note");
			if (!empty($sqlnote)) { if ($sqlnote == $setnote) { $sqlfoundnote = '1'; } }
		}
		if (isset($sqlfoundnote)) { $mysqldo = "DELETE FROM `bible_notes` WHERE `verse` = '".$note."' AND `user`='".$userfoundincheck."'"; }
		else { $mysqldo = "UPDATE `bible_notes` SET `note` = '".$setnote."',`datetime`= 'NOW()' WHERE `verse` = '".$note."' AND `user`='".$userfoundincheck."'"; }
		//UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value 
	}
	else { $mysqldo ="INSERT INTO `b`.`bible_notes` (`id`, `verse`, `user`, `datetime`,`note`) VALUES (NULL, '".$note."', '".$userfoundincheck."', NOW() ,'".$setnote."')"; }
	if (isset($mysqldo)) { $result8=mysql_query($mysqldo,$link); echo "<br>Note Edited"; }
} // <- set/update/remove note
elseif(!empty($setfavorite) && !empty($userfoundincheck)) { // set/remove favorite\s
	$result9=mysql_query("SELECT id FROM `bible_favorites` WHERE `favoriteverse`='".$setfavorite."' AND `user`='".$userfoundincheck."'", $link);
	$num9=mysql_numrows($result9);
	if ($num9>=1) { $mysqldo = "DELETE FROM `bible_favorites` WHERE `favoriteverse` = '".$setfavorite."' AND `user`='".$userfoundincheck."'"; }
	else { $mysqldo ="INSERT INTO `b`.`bible_favorites` (`id`, `favoriteverse`, `user`, `datetime`) VALUES (NULL, '".$setfavorite."', '".$userfoundincheck."', NOW())"; }
	$result9=mysql_query($mysqldo,$link);
	echo "Favorite Edited";
} // <- set/remove favorite\s
elseif(!empty($userfeatures) && !empty($userfoundincheck)) { // User Feature Page
	$featurelink_basis = "<a target='middleframe' href=".$_SERVER['PHP_SELF']."?";
	$featurelink_basis2 = preg_replace('/\s/','+',$userfeatures);
	$featurelink = "&#177".$featurelink_basis."setbookmark=".$featurelink_basis2.">Bookmark</a> ";
	$featurelink2 = "&#177".$featurelink_basis."setfavorite=".$featurelink_basis2.">Favorite</a> ";
	$featurelink3 = "-".$featurelink_basis."setnote=".$featurelink_basis2.">Note</a> ";
	$featurelink4 = $featurelink_basis."xref=".$featurelink_basis2.">xRefs</a> ";
	echo $featurelink4." ".$featurelink." ".$featurelink2." ".$featurelink3." ".$userfeatures."<br>";
	echo "<form action='index.php' method='get'><input type='hidden' name='note' value='".$userfeatures."'>";
	echo "<textarea name='setnote' rows='2' cols='100%'>";
	$sql10 = "SELECT * FROM `bible_notes` WHERE `verse`='".$userfeatures."' AND `user`='".$userfoundincheck."'";
	$result10=mysql_query($sql10, $link);
	$num10=mysql_numrows($result10);
	if ($num10>=1) {
		for($i=0; $i<$num10; $i++) {
			$sqlnote=mysql_result($result10,$i,"note");
			if (!empty($sqlnote)) { echo $sqlnote; }
		}
	}
	echo "</textarea>";
	echo "<br><input type='submit' value='Save' /></form>";
} // <- User Feature Page

//"<a href=".$_SERVER['PHP_SELF']."?s=".preg_replace('/\s/','+',$search)."&b=".$bible."&bk=".$book."&c=".$chap.">".$sqlcountbook."(".$sqlcountversenum.")</a>"
// <- BibleContentparser
if (empty($mysqldatabasecreate)) { mysql_close(); }
/*
    Bibelprat.Net, hereby disclaims all copyright interest in the program “Scripture For PHP” (which makes passes at compilers) written by Kriss(Krizoek).

    <signature of Kriss(krizoek)>, 3/4-2011
    Admin@Bibelprat.Net
	
*/
?>